/* freeircd types.c
 *
 * Iniciado em 02/08/2006
 */

#ifndef _TYPES_H
#include <stdbool.h>
#include <time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

#define MASK_NICK      0
#define MASK_IP        1
#define MASK_BOTH      2
#define MASK_EVERYBODY 3

#define USER_STATUS_IDENTIFIED 0
#define USER_STATUS_TO_IDENTIFY 1
#define USER_STATUS_OFFLINE 2

#define CHAN_STATUS_IDENTIFIED 0
#define CHAN_STATUS_TO_IDENTIFY 1
#define CHAN_STATUS_OFFLINE 2

typedef signed char veryshort;

typedef struct user_reg
{
        char *nick;
        char *password;
        char *nome;
        char *email;
        char *url;
        char *localizacao;
        char *last_mask;

        int kill_timeout;

        bool never_unreg;

        time_t reg_time;
        time_t last_time;

        time_t online_time;

        veryshort status;
        time_t ident_timeout;

        struct client_list *user;

        struct reg_notas
        {
                char *nota;
                int num;

                struct reg_notas *prev;
                struct reg_notas *next;
        } *notas;

        struct reg_ajoin
        {
                char *chan;

                struct reg_ajoin *prev;
                struct reg_ajoin *next;
        } *ajoins;

        struct user_reg *prev;
        struct user_reg *next;
} USERREG;

typedef struct chan_list
{
        char *name;
        char *topic;

        char *topic_set_by;
        time_t topic_seted;

        time_t created;

        struct chan_users_list /*lista te utilizadores*/
        {
                struct client_list *user;
                bool op;
                bool voice;
                bool secret;

                struct chan_users_list *prev;
                struct chan_users_list *next;
        } *users;

        struct chan_modes
        {
                bool t;
                bool m;
                bool s;
                bool c;
                char *key;
        } modes;

        struct ban_list
        {
                char *nick;
                char *md5_ip;

                char *banned_by;
                time_t banned_at;

                veryshort mask_type;

                struct ban_list *prev;
                struct ban_list *next;
        } *bans;

        struct chan_reg *reg;

        struct chan_list *prev;
        struct chan_list *next;
} CHANS;

typedef struct chan_reg
{
        char *founder;
        char *password;
        char *desc;
        char *email;
        char *url;

        struct access_users /*internamente feito*/
        {
                char *nick;
                veryshort level;
                int num;

                bool founder_access;

                struct access_users *prev;
                struct access_users *next;
        } *ausers;

        struct chan_akicks /*internamente feito*/
        {
                char *nick;
                char *md5_ip;

                veryshort mask_type;

                struct chan_akicks *prev;
                struct chan_akicks *next;
        } *akicks;

        struct chan_reg_set
        {
                bool priv;
                bool mode_lock; /*internamente feito*/
                bool topic_lock; /*internamente feito*/
                bool secure_ops; /*internamente feito*/
                bool restricted; /*internamente feito*/
        } set;

        struct chan_reg_levels
        {
                veryshort autoop; /*5*/ /*internamente feito*/
                veryshort autovoice; /*3*/ /*internamente feito*/
                veryshort autodeop; /*-1*/ /*internamente feito*/
                veryshort invite; /*5*/
                veryshort akick; /*10*/
                veryshort set; /*founder*/
                veryshort clear; /*founder*/
                veryshort unban; /*5*/
                veryshort opdeop; /*5*/
                veryshort kick; /*10*/
                veryshort nojoin; /*0*/ /*internamente feito*/
                veryshort access_list; /*5*/
                veryshort access_change; /*3 (so pode dar op < ao seu op; para apagar tem que ter op superior ao alvo)*/

                veryshort memo_read; /*5*/
                veryshort memo_send; /*5*/
                veryshort memo_del; /*15*/
        } levels;

        time_t reg_time;
        time_t last_use; /*internamente feito*/

        long users_record;
        time_t record_time;

        bool never_unreg;
} CHANREG;

typedef struct client_list
{
        int sd;
        struct sockaddr_in sock;
        socklen_t size;

        struct
        {
                char *buff;

                int size;
        } buffinfo;

        char *msg;
        bool msg_ok;
        long size_msg;
        long counter;

        veryshort do_welcome;

        time_t next_ping;
        time_t sent_ping; /*0 se não esta' a' espera de resposta*/

        time_t sign_on;
        time_t last_move; /*Para o idle*/

        char *nick;
        char *name;
        char *away;
        char *md5_ip;
        bool ircop;

        int error;
        bool killed;

        veryshort ident_failed;

        struct user_chans_list /*Lista de canais do utilizador*/
        {
                CHANS *chan;
                bool op;
                bool voice;
                bool secret;

                struct user_chans_list *prev;
                struct user_chans_list *next;
        } *chans;

        USERREG *reg;

        struct client_list *prev;
        struct client_list *next;
} CLIENTS;

typedef struct ircop_list
{
        char *username;
        unsigned char md5_hash[16];

        struct ircop_list *prev;
        struct ircop_list *next;
} IRCOPS;

typedef struct motd_list
{
        char *line;

        struct motd_list *next;
} MOTD;

#define _TYPES_H
#endif
